WorkflowConfigForm = Ext.extend(Ext.Window, {
    constructor : function(a) {
        Ext.applyIf(this, a);
        this.initUIComponents();
        WorkflowConfigForm.superclass.constructor.call(this, {
            layout : "fit",
            items : yearGridFormPanel,
            modal : true,
            bodyStyle : "padding:2px;",
            buttonAlign : "center",
            buttons : yearGridFormButtons,
            title : "流程配置信息", 
            iconCls : "menu-flowWait",
            width : 620,
            height : 350
        });
    },
    initUIComponents : function() {
        createyeargridform({
            operation : this,
            form : {
                saveUrl : __ctxPath + "/bpmndemo/saveWorkflowConfig.do",
                items : [ {
                    name : "workflowConfig.id",
                    xtype : "hidden",
                    value : this.id == null ? "" : this.id
                }, {
                    name : "workflowConfig.workflowKey",
                    xtype : "hidden",
                    value : this.processKey == null ? "" : this.processKey
                },{
                    name : "workflowConfig.taskName",
                    xtype : "hidden"
                }, {
                    name : "workflowConfig.companyName",
                    xtype : "hidden"
                },{
                    name : "workflowConfig.departmentName",
                    xtype : "hidden"
                },{
                    name : "workflowConfig.checkUserId",
                    xtype : "hidden"
                },
                {
                    layout : "column", // 第一行
                    bodyStyle : "padding:5px;",
                    items : [ {
                        columnWidth : .5,//第一行第1列
                        border : false,
                        layout : "form",
                        defaultType : "textfield",
                        items : [ {
                            fieldLabel : '流程名称' + '<font color=red>*</font>',
                            name : "workflowConfig.workflowName",
                            maxLength : 80,
                            width : 146,
                            readOnly: true,
                            allowBlank : false,
                            value : this.processName,
                            blankText : "流程名称不能为空！"
                        } ]
                    }, {
                        columnWidth : .5,//第一行第2列
                        border : false,
                        layout : "form",
                        defaultType : "textfield",
                        items : [ {
                            fieldLabel : "公司名称"+ '<font color=red>*</font>',
                            name : "workflowConfig.companyId",
                            maxLength : 80,
                            width : 146,
                            allowBlank : false,
                            blankText : "公司名称不能为空！"
                        } ]
                    }]
                },{
                    layout : "column",
                    bodyStyle : "padding:5px;",
                    items : [ {
                        columnWidth : .5,
                        layout : "form",
                        border : false,
                        defaultType : "textfield",
                        items : [ {
                            fieldLabel : "部门名称"+ '<font color=red>*</font>',
                            name : "workflowConfig.departmentId", 
                            maxLength : 80,
                            width : 146,
                            allowBlank : true,
                            blankText : "部门名称不能为空！"
                        } ]
                    },{ 
                        columnWidth:.5,//第一列 
                        layout:"form", 
                        border : false,
                        items:[{
                                xtype : "combo",
                                fieldLabel: '任务节点名称'+'<font color=red>*</font>', 
                                editable : false,
                                allowBlank : false,
                                width : 146,
                                hiddenName : "workflowConfig.taskId",
                                name : "workflowConfig.taskName",
                                mode : "local",
                                lazyInit : false,
                                forceSelection : false,
                                blankText : '任务节点名称不能为空！', 
                                emptyText : '请选择任务节点',           
                                triggerAction : "all",
                                store : new Ext.data.JsonStore({
                                    url : __ctxPath + "/bpmndemo/findTaskByBpmnXMLWorkflow.do?processDefinitionKey=" + this.processKey,
                                    autoLoad : true,
                                    autoShow : true,
                                    root : "result",
                                    idProperty : "id",
                                    fields : [ "id", "name","assignee","candidateUsers" ],
                                    listeners : {

                                    }
                                }),
                                valueField : "id",
                                displayField : "name",
                                listeners : {
                                    select:function(combo,record,index){
                                        var  userTask = record.data;
                                        var  taskType;
                                        if(!userTask.assignee){
                                            taskType=2
                                            var candidateUsers=userTask.candidateUsers[0];
                                            yearGridFormPanel.getCmpByName("workflowConfig.variableName").setValue(candidateUsers.substring(candidateUsers.indexOf("{")+1,candidateUsers.lastIndexOf("}")));
                                        }else{
                                            taskType=1
                                            var assignee=userTask.assignee
                                            yearGridFormPanel.getCmpByName("workflowConfig.variableName").setValue(assignee.substring(assignee.indexOf("{")+1,assignee.lastIndexOf("}")));
                                            
                                        }
                                        yearGridFormPanel.getCmpByName("taskTypeName").setValue(taskType); 
                                        yearGridFormPanel.getCmpByName("workflowConfig.taskName").setValue(userTask.name);
                                    }
                                }
                            }                                       
                          ] 
                    }]
                },{
                    layout : "column",
                    bodyStyle : "padding:5px;",
                    items : [{
                        layout : "form",
                        columnWidth : .5,
                        border : false,
                        items : [{ 
                                    xtype : "combo",
                                    fieldLabel : '任务类型' + '<font color=red>*</font>',
                                    editable : false,
                                    readOnly : true,
                                    allowBlank : false,
                                    width : 146,
                                    maxLength : 80,
                                    hiddenName : "workflowConfig.taskType",
                                    name : "taskTypeName",
                                    mode : "local",
                                    lazyInit : false,
                                    forceSelection : false,
                                    blankText : "任务类型不能为空！",
                                    emptyText : '请选择任务类型',           
                                    triggerAction : "all",
                                    store : new Ext.data.ArrayStore({  
                                        fields : ['taskType', 'taskTypeName'],  
                                        data : [["1","个人任务"],["2","组任务"]]  
                                    }),
                                    valueField : "taskType",
                                    displayField : "taskTypeName"
                                }                                       
                              ] 
                    },{
                        layout : "form",
                        columnWidth : .5,
                        border : false,
                        items : [{
                            xtype : "textfield",
                            fieldLabel : '变量名称' + '<font color=red>*</font>',
                            name : "workflowConfig.variableName",
                            readOnly : true,
                            width : 146,
                            maxLength : 80,
                            allowBlank : false,
                            blankText : "变量名称不能为空！"
                        } ]
                    }]
                },{
                    layout : "column",
                    bodyStyle : "padding:5px;",
                    items : [  {
                        layout : "form",
                        columnWidth : 1,
                        border : false,
                        items : [ {
                            xtype : "textarea",
                            fieldLabel : '审核人',
                            name : "workflowConfig.checkUserName",
                            width : 448,
                            maxLength : 80,
                        } ]
                    }]
                }]
            },
            loadData : {
                getUrl : __ctxPath + "/bpmndemo/getWorkflowConfig.do",
                preName : "workflowConfig"
            },
            //配置项意为双击打开后的form为只读
            isShow : this.isShow
        });
    }
});
